﻿using AdminSystem.Applications;
using AdminSystem.Domain.User;
using AdminSystem.Repositories;
using AdminSystem.Write.API.Command.TracebilitysDetile;
using AdminSystem.Write.API.DTOS;
using MediatR;

namespace AdminSystem.Write.API.Handers.TracebilitysDetileHander
{
    public class TracebilitysDetileCommandsHandler : IRequestHandler<TracebilitysDetileCommand, ApiResult<object>>
    {
        private readonly IRepository<Tracebility> repository;
        private readonly IRepository<Shopp> shoppRepository;

        public TracebilitysDetileCommandsHandler(IRepository<Tracebility> repository, IRepository<Shopp> ShoppRepository)
        {
            this.repository = repository;
            shoppRepository = ShoppRepository;
        }

        /// <summary>
        /// 查询溯源信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<object>> Handle(TracebilitysDetileCommand request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<object> ret = new ApiResult<object>();
                var traceadility = await repository.GetById(request.Id);

                if (traceadility != null)
                {
                    ret.statusCode = StatusCode.FaieId;
                    ret.Message = "溯源信息不存在";
                    ret.Data = traceadility;
                }
                else
                {
                    ret.statusCode = StatusCode.Success;
                    ret.Message = "查询成功";
                }
                return ret;
            }
            catch (Exception)
            {
                throw;
            }
        }


    }
}
